//
//  ItemRecord.m
//
//  Created by Jeremy Whitcher on 3/10/12.
//

#import "ItemRecord.h"

#define FILE_NAME              "FileName"
#define ITEM_TITLE_KEY         "ItemTitle"
#define ITEM_DESCRIPTION_KEY   "ItemDescription"
#define ITEM_CONTACT_KEY       "ItemContact"
#define ITEM_EMAIL_KEY         "ItemEmail"
#define ITEM_PHONE_KEY         "ItemPhone"
#define ITEM_EXCHANGE_KEY      "ItemExchange"
#define ITEM_LOCATION_KEY      "ItemLocation"
#define ITEM_PIC1              "ItemPic1"
#define ITEM_PIC2              "ItemPic2"
#define ITEM_THUMBNAIL1        "ItemThumbnail1"
#define ITEM_THUMBNAIL2        "ItemThumbnail2"
#define ITEM_METHOD_SALE_KEY   "ItemMethodSale"
#define ITEM_NUM_UPLOADS_KEY   "ItemNumUploads"
#define ITEM_NUM_PICS_KEY      "ItemNumPics"
#define ITEM_POST_TWITTER_KEY  "ItemPostTwitter"
#define ITEM_POST_FACEBOOK_KEY "ItemPostFacebook"

@implementation ItemRecord

@synthesize fileName;
@synthesize itemTitle;
@synthesize itemDescription;
@synthesize itemContact;
@synthesize itemEmail;
@synthesize itemPhone;
@synthesize itemExchange;
@synthesize itemLocation;
@synthesize itemPic1;
@synthesize itemPic2;
@synthesize itemThumbnail1;
@synthesize itemThumbnail2;
@synthesize itemMethodSale;
@synthesize itemNumUploads;
@synthesize itemNumPics;
@synthesize itemFbLastShare;
@synthesize itemTwLastShare;
@synthesize itemIncludeContactInfo;
@synthesize itemModified;
@synthesize itemDeleted;

-(void) encodeWithCoder: (NSCoder *) encoder
{    
    [encoder encodeObject: fileName         forKey: @FILE_NAME];
    [encoder encodeObject: itemTitle        forKey: @ITEM_TITLE_KEY];
    [encoder encodeObject: itemDescription  forKey: @ITEM_DESCRIPTION_KEY];
    [encoder encodeObject: itemContact      forKey: @ITEM_CONTACT_KEY];
    [encoder encodeObject: itemEmail        forKey: @ITEM_EMAIL_KEY];
    [encoder encodeObject: itemPhone        forKey: @ITEM_PHONE_KEY];
    [encoder encodeObject: itemExchange     forKey: @ITEM_EXCHANGE_KEY];
    [encoder encodeObject: itemLocation     forKey: @ITEM_LOCATION_KEY];
    [encoder encodeObject: itemPic1         forKey: @ITEM_PIC1];
    [encoder encodeObject: itemPic2         forKey: @ITEM_PIC2];
    [encoder encodeObject: itemThumbnail1   forKey: @ITEM_THUMBNAIL1];
    [encoder encodeObject: itemThumbnail2   forKey: @ITEM_THUMBNAIL2];
    [encoder encodeBool  : itemMethodSale   forKey: @ITEM_METHOD_SALE_KEY];
    [encoder encodeInt   : itemNumUploads   forKey: @ITEM_NUM_UPLOADS_KEY];
    [encoder encodeInt   : itemNumPics      forKey: @ITEM_NUM_PICS_KEY];
    [encoder encodeObject: itemTwLastShare  forKey: @ITEM_POST_TWITTER_KEY];
    [encoder encodeObject: itemFbLastShare  forKey: @ITEM_POST_FACEBOOK_KEY];
}

-(id) initWithCoder: (NSCoder *) decoder
{    
    fileName         = [decoder decodeObjectForKey: @FILE_NAME];
    itemTitle        = [decoder decodeObjectForKey: @ITEM_TITLE_KEY];
    itemDescription  = [decoder decodeObjectForKey: @ITEM_DESCRIPTION_KEY];
    itemContact      = [decoder decodeObjectForKey: @ITEM_CONTACT_KEY];
    itemEmail        = [decoder decodeObjectForKey: @ITEM_EMAIL_KEY];
    itemPhone        = [decoder decodeObjectForKey: @ITEM_PHONE_KEY];
    itemExchange     = [decoder decodeObjectForKey: @ITEM_EXCHANGE_KEY];
    itemLocation     = [decoder decodeObjectForKey: @ITEM_LOCATION_KEY];
    itemPic1         = [decoder decodeObjectForKey: @ITEM_PIC1];
    itemPic2         = [decoder decodeObjectForKey: @ITEM_PIC2];
    itemThumbnail1   = [decoder decodeObjectForKey: @ITEM_THUMBNAIL1];
    itemThumbnail2   = [decoder decodeObjectForKey: @ITEM_THUMBNAIL2];
    itemMethodSale   = [decoder decodeBoolForKey  : @ITEM_METHOD_SALE_KEY];
    itemNumUploads   = [decoder decodeIntForKey   : @ITEM_NUM_UPLOADS_KEY];
    itemNumPics      = [decoder decodeIntForKey   : @ITEM_NUM_PICS_KEY];
    itemTwLastShare  = [decoder decodeObjectForKey: @ITEM_POST_TWITTER_KEY];
    itemFbLastShare  = [decoder decodeObjectForKey: @ITEM_POST_FACEBOOK_KEY];
    
    itemIncludeContactInfo = false;
    itemModified           = false;
    itemDeleted            = false;
    
    return self;
}

-(id)copyWithZone:(NSZone *)zone
{
    ItemRecord *newItemRecord = [[ItemRecord alloc] init];
    
    [newItemRecord setFileName:               [self fileName]];
    [newItemRecord setItemTitle:              [self itemTitle]];
    [newItemRecord setItemDescription:        [self itemDescription]];
    [newItemRecord setItemContact:            [self itemContact]];
    [newItemRecord setItemEmail:              [self itemEmail]];
    [newItemRecord setItemPhone:              [self itemPhone]];
    [newItemRecord setItemExchange:           [self itemExchange]];
    [newItemRecord setItemLocation:           [self itemLocation]];
    [newItemRecord setItemPic1:               [self itemPic1]];
    [newItemRecord setItemPic2:               [self itemPic2]];
    [newItemRecord setItemThumbnail1:         [self itemThumbnail1]];
    [newItemRecord setItemThumbnail2:         [self itemThumbnail2]]; 
    [newItemRecord setItemFbLastShare:        [self itemFbLastShare]];
    [newItemRecord setItemTwLastShare:        [self itemTwLastShare]];
    [newItemRecord setItemMethodSale:         [self itemMethodSale]];
    [newItemRecord setItemNumUploads:         [self itemNumUploads]];
    [newItemRecord setItemNumPics:            [self itemNumPics]];
    [newItemRecord setItemTwLastShare:        [self itemTwLastShare]];
    [newItemRecord setItemFbLastShare:        [self itemFbLastShare]];
    [newItemRecord setItemIncludeContactInfo: [self itemIncludeContactInfo]];
    [newItemRecord setItemModified:           [self itemModified]];
    [newItemRecord setItemDeleted:            [self itemDeleted]];
    return newItemRecord;
}

@end
